import dayjs from "dayjs";
export const getNewDate = (date) => {
  const year = date.getFullYear();
  const month = date.getMonth();
  const day = date.getDate();
  return {
    year,
    month,
    day,
  };
};

export const getDate = (year, month, day) => {
  return new Date(year, month, day);
};

export const formatDate = (date) => {
  date = Number(date);
  return date < 10 ? `0${date}` : date;
};

export const workingDays = {
  workingDayFri: 5,
  workingDayMon: 1,
  workingDaySat: 6,
  workingDaySon: 0,
  workingDayTue: 2,
  workingDayTur: 4,
  workingDayWed: 3,
};

export const colorList = [
  {
    name: "休",
    c_background: "rgba(235,51,51,.05)",
    t_background: "#eb3333",
    color: "#eb3333",
  },
  {
    name: "班",
    c_background: "rgba(236, 245, 255, 0.8)",
    t_background: "#4e5877",
    color: "#333",
  },
  {
    name: "今",
    c_background: "#4e6ef2",
    t_background: "#6b88ff",
    color: "#fff",
  },
  {
    name: "",
    c_background: "#F2AF33",
    t_background: "",
  },
];

export const isWhichDay = (value: Date, whichDay: any[]) => {
  const today = new Date(value);
  const dayOfWeek = today.getDay();
  const isFree = whichDay.indexOf(dayOfWeek) !== -1 ? true : false;
  return isFree;
};

export function getDatesBetween(startDate: any, endDate: any) {
  const nowStartDate = new Date(startDate);
  const nowEndDate = new Date(endDate);
  const dates = [];
  const current = new Date(nowStartDate);

  while (current <= nowEndDate) {
    dates.push(dayjs(new Date(current)).format("YYYY-MM-DD"));
    current.setDate(current.getDate() + 1);
  }

  return dates;
}
